class Solution {
    public:
        int findMaxForm(vector<string>& strs, int m, int n) {
            int num = strs.size();
            vector<vector<vector<int>>> dp(num+1,vector<vector<int>>(m+1,vector<int>(n+1)));
            for(int i = 1 ; i < num+1 ;i++){
                for(int j = 0 ; j < m+1;j++){
                    for(int k = 0 ; k < n+1 ;k++){
                        int zero =0,one = 0,sum = strs[i-1].size();
                        for(int x = 0 ; x < sum ;x++){
                            if(strs[i-1][x] == '0') zero++;
                            else one++;
                        }
                        dp[i][j][k] = j >= zero && k>= one? max(dp[i-1][j][k],dp[i-1][j-zero][k-one]+1):dp[i-1][j][k];
                    }
                }
            }
            return dp[num][m][n];
        }
    };